package com.job.DQH.dqh715.inClass;

import java.util.Arrays;

public class String04 {
    public static void main(String[] args) {
        String name = "xtspur_abcdef_ghijkl_mnopqr_stuvwx_yz";
        String newname = name.replace('x','a');//将x替换为a
        System.out.println(newname);

        String newname2 = name.replace("xtspur","XTSPUR");//字符串同理
        System.out.println(newname2);

        String[] names = name.split("_");//分割处，将字符串分割为多个字符串赋给字符串数组，分割处会被舍去
        System.out.println(Arrays.toString(names));
        String[] names2 = name.split("_",2);//分割上限为2次
        System.out.println(Arrays.toString(names2));

        //substring(int x,int y)方法，截取从下标x至下标y的字符串
        String url = "https://pages.tmall.com/wow/a/act/tmall/dailygroup/1996";
        int index = url.indexOf("https");
        int end = url.indexOf("com");
        System.out.println(url.substring(index,end+3));//输出域名
    }
}
